{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f04dd603-a2d1-48ce-8c17-9f1dba8de1ee",
   "metadata": {},
   "source": [
    "Chapter 01\n",
    "\n",
    "# 向量加法\n",
    "《线性代数》 | 鸢尾花书：数学不难"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccafb456-2453-4c82-8a65-b1963a370cb2",
   "metadata": {},
   "source": [
    "代码的目标是演示**向量加法**的数学原理，并计算两个二维向量的和。我们详细分析其数学背景和计算过程。\n",
    "\n",
    "---\n",
    "\n",
    "### **1. 向量的数学表示**\n",
    "在二维欧几里得空间 $\\mathbb{R}^2$ 中，一个向量可以表示为：\n",
    "\n",
    "$$\n",
    "\\mathbf{a} = \\begin{bmatrix} a_1 \\\\ a_2 \\end{bmatrix}, \\quad\n",
    "\\mathbf{b} = \\begin{bmatrix} b_1 \\\\ b_2 \\end{bmatrix}\n",
    "$$\n",
    "\n",
    "在代码中：\n",
    "- 向量 $\\mathbf{a}$ 由 `a_vec = np.array([4, 1])` 赋值，其中 $a_1 = 4, a_2 = 1$。\n",
    "- 向量 $\\mathbf{b}$ 由 `b_vec = np.array([1, 2])` 赋值，其中 $b_1 = 1, b_2 = 2$。\n",
    "\n",
    "---\n",
    "\n",
    "### **2. 向量加法的数学定义**\n",
    "向量加法的运算规则是按分量相加，即：\n",
    "\n",
    "$$\n",
    "\\mathbf{a} + \\mathbf{b} =\n",
    "\\begin{bmatrix} a_1 \\\\ a_2 \\end{bmatrix} +\n",
    "\\begin{bmatrix} b_1 \\\\ b_2 \\end{bmatrix} =\n",
    "\\begin{bmatrix} a_1 + b_1 \\\\ a_2 + b_2 \\end{bmatrix}\n",
    "$$\n",
    "\n",
    "代入具体数值：\n",
    "\n",
    "$$\n",
    "\\begin{bmatrix} 4 \\\\ 1 \\end{bmatrix} +\n",
    "\\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix} =\n",
    "\\begin{bmatrix} 4 + 1 \\\\ 1 + 2 \\end{bmatrix} =\n",
    "\\begin{bmatrix} 5 \\\\ 3 \\end{bmatrix}\n",
    "$$\n",
    "\n",
    "在代码中：\n",
    "```python\n",
    "a_plus_b = a_vec + b_vec\n",
    "```\n",
    "执行的是 NumPy 数组的逐元素加法，返回 $\\begin{bmatrix} 5 \\\\ 3 \\end{bmatrix}$。\n",
    "\n",
    "---\n",
    "\n",
    "### **3. 计算结果**\n",
    "执行 `a_plus_b` 之后，Python 计算出的结果是：\n",
    "```python\n",
    "array([5, 3])\n",
    "```\n",
    "这正是数学计算得出的 $\\mathbf{a} + \\mathbf{b}$ 的值。\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6e57ed8-33df-433f-9e7e-717f21e198d6",
   "metadata": {},
   "source": [
    "## 初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "79c8f4f2-d504-41f4-82e5-a06716cbf6ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6670ff2f-380b-4932-b22b-cbfe2efc825b",
   "metadata": {},
   "source": [
    "## 定义向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e28b3f7e-8fbe-4ba4-91dd-010623fbd111",
   "metadata": {},
   "outputs": [],
   "source": [
    "a_vec = np.array([4, 1])\n",
    "b_vec = np.array([1, 2])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf0bea02-16b3-4340-86d1-ffcd2f1835de",
   "metadata": {},
   "source": [
    "## 向量加法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3a48970a-ea1f-4c59-968a-dcdb1f0d5daf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 3])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_plus_b = a_vec + b_vec\n",
    "a_plus_b"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "582f5109-82df-4493-bf02-0152e0603fe8",
   "metadata": {},
   "source": [
    "作者\t**生姜DrGinger**  \n",
    "脚本\t**生姜DrGinger**  \n",
    "视频\t**崔崔CuiCui**  \n",
    "开源资源\t[**GitHub**](https://github.com/Visualize-ML)  \n",
    "平台\t[**油管**](https://www.youtube.com/@DrGinger_Jiang)\t\t\n",
    "\t\t[**iris小课堂**](https://space.bilibili.com/3546865719052873)\t\t\n",
    "\t\t[**生姜DrGinger**](https://space.bilibili.com/513194466)  "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
